package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TNotes;
import com.ruoyi.system.service.ITNotesService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 备注信息Controller
 * 
 * @author ruoyi
 * @date 2024-12-20
 */
@Controller
@RequestMapping("/system/notes")
public class TNotesController extends BaseController
{
    private String prefix = "system/notes";

    @Autowired
    private ITNotesService tNotesService;

    @RequiresPermissions("system:notes:view")
    @GetMapping()
    public String notes()
    {
        return prefix + "/notes";
    }

    /**
     * 查询备注信息列表
     */
    @RequiresPermissions("system:notes:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TNotes tNotes)
    {
        startPage();
        List<TNotes> list = tNotesService.selectTNotesList(tNotes);
        return getDataTable(list);
    }

    /**
     * 导出备注信息列表
     */
    @RequiresPermissions("system:notes:export")
    @Log(title = "备注信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TNotes tNotes)
    {
        List<TNotes> list = tNotesService.selectTNotesList(tNotes);
        ExcelUtil<TNotes> util = new ExcelUtil<TNotes>(TNotes.class);
        return util.exportExcel(list, "备注信息数据");
    }

    /**
     * 新增备注信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存备注信息
     */
    @RequiresPermissions("system:notes:add")
    @Log(title = "备注信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TNotes tNotes)
    {
        return toAjax(tNotesService.insertTNotes(tNotes));
    }

    /**
     * 修改备注信息
     */
    @RequiresPermissions("system:notes:edit")
    @GetMapping("/edit/{notesId}")
    public String edit(@PathVariable("notesId") Long notesId, ModelMap mmap)
    {
        TNotes tNotes = tNotesService.selectTNotesByNotesId(notesId);
        mmap.put("tNotes", tNotes);
        return prefix + "/edit";
    }

    /**
     * 修改保存备注信息
     */
    @RequiresPermissions("system:notes:edit")
    @Log(title = "备注信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TNotes tNotes)
    {
        return toAjax(tNotesService.updateTNotes(tNotes));
    }

    /**
     * 删除备注信息
     */
    @RequiresPermissions("system:notes:remove")
    @Log(title = "备注信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tNotesService.deleteTNotesByNotesIds(ids));
    }
}
